package com.cykj.pos.controller.api;

import java.util.List;
import java.util.Arrays;

import com.cykj.pos.domain.*;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cykj.common.annotation.Log;
import com.cykj.common.core.controller.BaseController;
import com.cykj.common.core.domain.AjaxResult;
import com.cykj.common.enums.BusinessType;
import com.cykj.pos.service.IAizProfitSharingRecordService;
import com.cykj.common.utils.poi.ExcelUtil;
import com.cykj.common.core.page.TableDataInfo;

/**
 * 分润记录Controller
 *
 * @author weijianbo
 * @date 2025-01-22
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/Profit/sharing" )
public class AizProfitSharingRecordController extends BaseController {

    private final IAizProfitSharingRecordService iAizProfitSharingRecordService;

    /**
     * 查询分润记录列表
     */
//    @PreAuthorize("@ss.hasPermi('pos:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(AizProfitSharingRecord aizProfitSharingRecord) {
        startPage();
        List<AizProfitSharingRecord> list = iAizProfitSharingRecordService.queryList(aizProfitSharingRecord);
        return getDataTable(list);
    }

    /**
     * 导出分润记录列表
     */
    @PreAuthorize("@ss.hasPermi('pos:record:export')" )
    @Log(title = "分润记录" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(AizProfitSharingRecord aizProfitSharingRecord) {
        List<AizProfitSharingRecord> list = iAizProfitSharingRecordService.queryList(aizProfitSharingRecord);
        ExcelUtil<AizProfitSharingRecord> util = new ExcelUtil<AizProfitSharingRecord>(AizProfitSharingRecord.class);
        return util.exportExcel(list, "record" );
    }

    /**
     * 获取分润记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('pos:record:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Integer id) {
        return AjaxResult.success(iAizProfitSharingRecordService.getById(id));
    }

    /**
     * 新增分润记录
     */
    @PreAuthorize("@ss.hasPermi('pos:record:add')" )
    @Log(title = "分润记录" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AizProfitSharingRecord aizProfitSharingRecord) {
        return toAjax(iAizProfitSharingRecordService.save(aizProfitSharingRecord) ? 1 : 0);
    }

    /**
     * 修改分润记录
     */
    @PreAuthorize("@ss.hasPermi('pos:record:edit')" )
    @Log(title = "分润记录" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AizProfitSharingRecord aizProfitSharingRecord) {
        return toAjax(iAizProfitSharingRecordService.updateById(aizProfitSharingRecord) ? 1 : 0);
    }

    /**
     * 删除分润记录
     */
    @PreAuthorize("@ss.hasPermi('pos:record:remove')" )
    @Log(title = "分润记录" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(iAizProfitSharingRecordService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }


    //商户交易统计
    @GetMapping("/transRecord")
    public TableDataInfo transRecord(BizMerchantTranStatistics BizMerchantTranStatistics) {
//        startPage();
        List<BizMerchantTranStatistics> list = iAizProfitSharingRecordService.queryTransRecord(BizMerchantTranStatistics);
        return getDataTable(list);
    }
    //商户交易统计 导出
    @GetMapping("/exportRecord" )
    public AjaxResult exportRecord(BizMerchantTranStatistics BizMerchantTranStatistics) {
        List<BizMerchantTranStatistics> list = iAizProfitSharingRecordService.queryTransRecord(BizMerchantTranStatistics);
        ExcelUtil<BizMerchantTranStatistics> util = new ExcelUtil<BizMerchantTranStatistics>(BizMerchantTranStatistics.class);
        return util.exportExcel(list, "record" );
    }


    //代理交易统计
    @GetMapping("/merchRecord")
    public TableDataInfo merchRecord(BizMerchantTranStatisticsMerchantExport bizMerchantTranStatisticsMerchantExport) {
//        startPage();
        List<BizMerchantTranStatisticsMerchantExport> list = iAizProfitSharingRecordService.queryMerchRecord(bizMerchantTranStatisticsMerchantExport);
        return getDataTable(list);
    }

    //代理交易统计 导出
    @GetMapping("/exportRecordMerch" )
    public AjaxResult exportRecordMerch(BizMerchantTranStatisticsMerchantExport bizMerchantTranStatisticsMerchantExport) {
        List<BizMerchantTranStatisticsMerchantExport> list = iAizProfitSharingRecordService.queryMerchRecord(bizMerchantTranStatisticsMerchantExport);
        ExcelUtil<BizMerchantTranStatisticsMerchantExport> util = new ExcelUtil<BizMerchantTranStatisticsMerchantExport>(BizMerchantTranStatisticsMerchantExport.class);
        return util.exportExcel(list, "record" );
    }

    //代理提现统计
    @GetMapping("/withdrawalRecord")
    public TableDataInfo withdrawalRecord(BizMerchantTranStatisticsWithdrawalExport bizMerchantTranStatisticsWithdrawalExport) {
        startPage();
        List<BizMerchantTranStatisticsWithdrawalExport> list = iAizProfitSharingRecordService.withdrawalRecord(bizMerchantTranStatisticsWithdrawalExport);
        return getDataTable(list);
    }

    //代理提现统计 导出
    @GetMapping("/exportWithdrawalRecord" )
    public AjaxResult exportWithdrawalRecord(BizMerchantTranStatisticsWithdrawalExport bizMerchantTranStatisticsWithdrawalExport) {
        List<BizMerchantTranStatisticsWithdrawalExport> list = iAizProfitSharingRecordService.withdrawalRecord(bizMerchantTranStatisticsWithdrawalExport);
        ExcelUtil<BizMerchantTranStatisticsWithdrawalExport> util = new ExcelUtil<BizMerchantTranStatisticsWithdrawalExport>(BizMerchantTranStatisticsWithdrawalExport.class);
        return util.exportExcel(list, "record" );
    }

    // 统计查询
    @PostMapping("/revenueStatistics")
    public AjaxResult revenueStatistics(@RequestBody BizMerchantTranStatistics bizMerchantTranStatistics){
        return iAizProfitSharingRecordService.revenueStatistics(bizMerchantTranStatistics);
    }


}
